﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="clr-namespace:AppToolkit.WPF.UI.Converters"
    xmlns:local="clr-namespace:AppToolkit.WPF.UI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="AppToolkit.WPF.UI.MultiThreadedFolderBrowser"
    d:DesignWidth="100" d:DesignHeight="80"
    >
    <DockPanel LastChildFill="True">
        <TreeView x:Name="foldersTree" Background="{DynamicResource {x:Static SystemColors.AppWorkspaceBrushKey}}">
            <TreeView.Resources>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate DataType="ContentPresenter">
                                <Grid>
                                    <StackPanel x:Name="spImg" Orientation="Horizontal">
                                        <Image x:Name="img"  
                                               Source="{Binding (local:TreeViewItemProps.ItemImageName), RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}" 
                                               Width="20" Height="20"  Stretch="Fill" VerticalAlignment="Center" />
                                        <TextBlock Text="{Binding}" Margin="5,0" VerticalAlignment="Center" />
                                        <Button x:Name="btnReload" 
                                                Visibility="{Binding (local:TreeViewItemProps.IsCanceled), Converter={x:Static conv:BoolToVisiblityConverter.Instance}, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                                                Tag="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}, Mode=FindAncestor}}"
                                                Click="btnReload_Click"
                                                Height="14" VerticalAlignment="Center" >
                                            <TextBlock FontSize="9" Text="Reload..." TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                        </Button>
                                        <!--<StackPanel Name="spLoading" Orientation="Horizontal"
                                                Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, 
                                                            Path=(local:TreeViewItemProps.IsLoading),
                                                            Converter={x:Static conv:vc_BoolToVisiblity.Instance}}"
                                                >
                                            <Grid Height="13"  MinWidth="50" MaxWidth="75" Margin="5,0" >
                                                <ProgressBar Name="pbLoading" Height="13"  MinWidth="50" MaxWidth="75" IsIndeterminate="True" HorizontalAlignment="Center" VerticalAlignment="Center">
                                                </ProgressBar>
                                                <TextBlock Name="txtLoading" Text="Loading..." FontSize="8.6" Margin="5,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                            </Grid>
                                            <Button Name="btnCancelLoad" 
                                                IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}, 
                                                            Path=(local:TreeViewItemProps.IsCanceled),
                                                            Converter={x:Static conv:vc_FlipBool.Instance}}"
                                                Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeViewItem}}}"
                                                Height="14" Click="btnCancelLoad_Click" VerticalAlignment="Center" >
                                                <TextBlock FontSize="9" Text="Cancel" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
                                            </Button>
                                        </StackPanel>-->
                                    </StackPanel>
                                </Grid>

                                <!--Visiblity Could Also be set via Triggers-->
                                <!--<DataTemplate.Triggers>

                                    <DataTrigger Binding="{Binding 
                                                           RelativeSource={RelativeSource 
                                                                            Mode=FindAncestor, 
                                                                            AncestorType={x:Type TreeViewItem}},
                                                                            Path=(local:TreeViewItemProps.IsLoading)}" 
                                                 Value="True">
                                        <Setter TargetName="spLoading" Property="Visibility" Value="Visible" />
                                    </DataTrigger>

                                    <DataTrigger Binding="{Binding 
                                                           RelativeSource={RelativeSource 
                                                                            Mode=FindAncestor, 
                                                                            AncestorType={x:Type TreeViewItem}}, 
                                                                            Path=(local:TreeViewItemProps.IsLoading)}" 
                                                 Value="False">
                                        <Setter TargetName="spLoading" Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                </DataTemplate.Triggers>-->
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TreeView.Resources>
        </TreeView>
    </DockPanel>
</UserControl>